﻿using Kz.Telegram.Bot.Console.Helpers;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.InlineQueryResults;
using Telegram.Bot.Types.ReplyMarkups;

namespace Kz.Telegram.Bot.Console.HandleUpdate
{
    public class InlineQueryHandler : IHandler
    {
        public async Task Handle(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
        {
            var q = update.InlineQuery;

            var inlineQueryId = q.Id;
            var keyword = q.Query.Trim().ToLower();

            if (keyword == string.Empty)
            {
                return;
            }

            List<InlineQueryResult> results = [];

            switch (keyword)
            {
                case "gif":
                    {
                        results.Add(new InlineQueryResultCachedSticker(id: SnowflakeHelper.NextId(), stickerFileId: "CAACAgUAAxkBAAMeZdv5A3h6AYqp1kcJTQfk7kx6pq4AAl0MAAJdVRBV3FHsS77eP400BA"));
                        results.Add(new InlineQueryResultCachedSticker(id: SnowflakeHelper.NextId(), stickerFileId: "CAACAgUAAxkBAAMfZdv5GoJNXE__QjdbFhd2q_YZDDsAAqAFAAKF_xBV3FOTBEXnp4k0BA"));
                        results.Add(new InlineQueryResultCachedSticker(id: SnowflakeHelper.NextId(), stickerFileId: "CAACAgUAAxkBAAMgZdv5TrpvcXqpiaHIHAzJQUbmiFIAAp8GAALE5hFVEsfANJp5_8w0BA"));
                    }
                    break;
                case "list":
                    {
                        InlineKeyboardButton[] inlineKeyboardButtons = [
                                InlineKeyboardButton.WithCallbackData(text: "赠送", callbackData: "yes"),
                                InlineKeyboardButton.WithCallbackData(text: "取消", callbackData: "no"),
                        ];
                        results.Add(new InlineQueryResultArticle(
                            id: SnowflakeHelper.NextId(),
                            title: "逼兜",
                            inputMessageContent: new InputTextMessageContent("打赏主播一个狠狠的大逼兜,让他喜欢上你"))
                        {
                            ReplyMarkup = new InlineKeyboardMarkup(inlineKeyboardButtons),
                            Description = "逼兜",
                            ThumbnailUrl = "http://121.37.137.76/sitefiles/library/images/2024/2/4b08280dd57a03fc.jpg",
                            ThumbnailWidth = 320,
                            ThumbnailHeight = 320
                        });
                        results.Add(new InlineQueryResultArticle(
                            id: SnowflakeHelper.NextId(),
                            title: "绿茶",
                            inputMessageContent: new InputTextMessageContent("打赏主播一大杯暖暖的绿茶,让他离不开你"))
                        {
                            ReplyMarkup = new InlineKeyboardMarkup(inlineKeyboardButtons),
                            Description = "绿茶",
                            ThumbnailUrl = "http://121.37.137.76/sitefiles/library/images/2024/2/4b08280dd57a03fc.jpg",
                            ThumbnailWidth = 320,
                            ThumbnailHeight = 320
                        });
                        results.Add(new InlineQueryResultArticle(
                            id: SnowflakeHelper.NextId(),
                            title: "嘉年华",
                            inputMessageContent: new InputTextMessageContent("打赏主播一套嘉年华,让她每天对你笑开颜"))
                        {
                            ReplyMarkup = new InlineKeyboardMarkup(inlineKeyboardButtons),
                            Description = "嘉年华",
                            ThumbnailUrl = "http://121.37.137.76/sitefiles/library/images/2024/2/4b08280dd57a03fc.jpg",
                            ThumbnailWidth = 320,
                            ThumbnailHeight = 320
                        });
                    }
                    break;
                default:
                    break;
            }

            if (results.Count > 0)
            {
                await botClient.AnswerInlineQueryAsync(inlineQueryId, results, cacheTime: 0, cancellationToken: cancellationToken);
            }
        }
    }
}